package com.dykj.fireFighting.web.base.app;

import com.dykj.fireFighting.api.base.maintenanceReply.entity.MaintenanceReply;
import com.dykj.fireFighting.common.core.annotation.AutoLog;
import com.dykj.fireFighting.common.core.api.CommonResult;
import com.dykj.fireFighting.common.starter.redisson.service.RedisService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;

import java.net.URL;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;

@Slf4j
@Api(value = "url重定向接口", tags = {"url重定向接口"})
@Controller
@RequestMapping(value = "/ts")
public class AppUrlController {
    @Autowired
    private RedisService redisService;
    @AutoLog(value = "url重定向接口")
    @ApiOperation(value = "url重定向接口", notes = "url重定向接口")
    @GetMapping("/a/{code}")
    //@RequiresPermissions("app/maintenanceReply/info")
    public ModelAndView urlInfo(@PathVariable("code") String code) throws UnsupportedEncodingException {
        Object o=redisService.get(code);
        String url="";
        if(null != o){
            url=redisService.get(code).toString();
        }
        //url="http://www.baidu.com";
        return new ModelAndView("redirect:" + url);
    }
    @GetMapping("/test/{id}")
    @ResponseBody
    //@RequiresPermissions("app/maintenanceReply/info")
    public CommonResult urlInfo1(@PathVariable("id") String id) throws UnsupportedEncodingException {
        Map m=new HashMap();
        m.put("name","账号");
        m.put("age","100");
        m.put("id",id);
        return CommonResult.success(m);
    }

}
